﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.util {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import Classes.*;
    import flash.system.*;
    import flash.net.*;

    public class BundleLoader {

        private var bundleLocator:String;
        private var bundleHandler:Function;

        public function BundleLoader(_arg1:String){
            this.bundleLocator = _arg1;
        }
        public function load(_arg1:Function):void{
            var _local3:String;
            this.bundleHandler = _arg1;
            var _local2:URLLoader = new URLLoader();
            _local2.dataFormat = URLLoaderDataFormat.BINARY;
            _local2.addEventListener(Event.COMPLETE, this.onBytesComplete);
            _local2.addEventListener(IOErrorEvent.IO_ERROR, this.onIOError);
            if (this.bundleLocator.indexOf("..") == 0){
                _local2.load(new URLRequest(this.bundleLocator));
            } else {
                _local3 = AssetUrlManager.instance.lookUpUrl(Global.getAssetURL(this.bundleLocator));
                _local2.load(new URLRequest(_local3));
            };
        }
        private function onBytesComplete(_arg1:Event):void{
            var _local2:ByteArray = (_arg1.target as URLLoader).data;
            var _local3:Loader = new Loader();
            var _local4:LoaderContext = new LoaderContext();
            _local4.applicationDomain = ApplicationDomain.currentDomain;
            _local3.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onBundleLoaded);
            _local3.loadBytes(_local2, _local4);
        }
        protected function onIOError(_arg1:IOErrorEvent):void{
            if (this.bundleHandler != null){
                this.bundleHandler(_arg1);
            };
        }
        private function onBundleLoaded(_arg1:Event):void{
            ItemImageAsset.injectAssets(_arg1.target.content);
            AlbumManager.injectSounds(_arg1.target.content);
            if (this.bundleHandler != null){
                this.bundleHandler(_arg1);
            };
        }

    }
}//package Classes.util 
